package com.helen.adapter;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.helen.entity.AllCommentEntity;
import com.helen.shopping.R;
import com.helen.utils.ImageLoadUtil;
import com.helen.utils.MyLog;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by yang on 2018/5/2.
 */

public class AllCommentListAdapter extends BaseQuickAdapter<AllCommentEntity, BaseViewHolder> {

    public AllCommentListAdapter(int layoutResId, List<AllCommentEntity> data) {
        super(layoutResId, data);

    }

    @Override
    protected void convert(final BaseViewHolder helper, final AllCommentEntity item) {
        try {
            CircleImageView imgUser = (CircleImageView) helper.getView(R.id.img_user);
            TextView tvCommentName = (TextView) helper.getView(R.id.tv_comment_name);
            TextView tvCommentTime = (TextView) helper.getView(R.id.tv_comment_time);
            TextView tvCommentContent = (TextView) helper.getView(R.id.tv_comment_content);
            RatingBar ratingBar = (RatingBar)helper.getView(R.id.rating_bar);
            RecyclerView rvCommentImg = (RecyclerView) helper.getView(R.id.rv_comment_img);
            ImageLoadUtil.displayImage(mContext, imgUser, item.getUserimg(), R.mipmap.app_logo, R.mipmap.app_logo);
            tvCommentName.setText(item.getUsername());
            tvCommentTime.setText(item.getTime());
            tvCommentContent.setText(item.getContent());
            ratingBar.setRating(item.getLevel());

            List<String> commentImgList = new ArrayList<>();
            for (int i = 0;i<item.getImgs().size();i++){
                commentImgList.add(item.getImgs().get(i).getUrl());
            }
            SingleImgAdapter  commentImgAdapter = new SingleImgAdapter(R.layout.item_comment_img_recycler, commentImgList);
            rvCommentImg.setLayoutManager(new GridLayoutManager(mContext, 4));
            rvCommentImg.setAdapter(commentImgAdapter);

        } catch (Exception e) {
            MyLog.e("yang", "评论列表异常" + e.toString());
        }


    }


}
